package web.servlet.request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author Administrator
 * @Date 2020/5/14 15:42
 **/
@WebServlet("/requestDome1")
public class RequestDome1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String contextPath = req.getContextPath();
        String servletPath = req.getServletPath();
        //路径
        StringBuffer requestURL = req.getRequestURL();
        String requestURI = req.getRequestURI();
        //  路径
        System.out.println(contextPath);
        System.out.println(servletPath);
        System.out.println(requestURL);
        System.out.println(requestURI);
        String method = req.getMethod();
        System.out.println(method);
        String header = req.getHeader("User-Agent");
        System.out.println(header);
        if(header.contains("Chrome")){
            System.out.println("谷歌浏览器");
        }else if(header.contains("Firefox")) {
            System.out.println("火狐浏览器");
        }else {
            System.out.println("其他浏览器");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
